import {Body, Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post,} from '@nestjs/common';
import {ServerTypeService} from './server-type.service';
import {CreateServerTypeDto} from './dto/create-server-type.dto';
import {UpdateServerTypeDto} from './dto/update-server-type.dto';
import {ApiResponse, ApiTags} from "@nestjs/swagger";
import {ServerTypeEntity} from "./entities/server-type.entity";

@ApiTags('server-type')
@Controller('server-type')
export class ServerTypeController {
    constructor(private readonly serverTypeService: ServerTypeService) {
    }

    @Post()
    async create(@Body() createServerTypeDto: CreateServerTypeDto) {
        return new ServerTypeEntity(await this.serverTypeService.create(createServerTypeDto));
    }

    @Get()
    @ApiResponse({type: ServerTypeEntity})
    async findAll() {
        const serverTypes = await this.serverTypeService.findAll();
        return serverTypes.map((serverType) => new ServerTypeEntity(serverType));
    }

    @Get(':id')
    async findOne(@Param('id', ParseUUIDPipe) id: string) {
        return new ServerTypeEntity(await this.serverTypeService.findOne(id));
    }

    @Patch(':id')
    async update(
        @Param('id', ParseUUIDPipe) id: string,
        @Body() updateServerTypeDto: UpdateServerTypeDto,
    ) {
        return new ServerTypeEntity(
            await this.serverTypeService.update(id, updateServerTypeDto)
        );
    }

    @Delete(':id')
    async remove(@Param('id',ParseUUIDPipe) id: string) {
        return new ServerTypeEntity(await this.serverTypeService.remove(id));
    }
}
